﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Data.SqlClient;
using Support.DTO;

namespace DataAccess
{
    public class TipoHabitoToxicoDAL : BaseSQLDAL
    {
        public List<TipoHabitoToxicoDTO> GetTiposHabitosToxicos()
        {
            List<TipoHabitoToxicoDTO> listaTipos = new List<TipoHabitoToxicoDTO>();

            try
            {

                CreateCommand("TipoHabitoToxico_Listado", true);

                ExecuteReader();
                while (Read())
                {
                    listaTipos.Add(FillDTO(GetDataReader()));
                }
                return listaTipos;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                DisposeDataReader();
                CloseConnection();
            }
        }

        private TipoHabitoToxicoDTO FillDTO(SqlDataReader reader)
        {
            return new TipoHabitoToxicoDTO()
            {
                Id = reader.GetInt32(reader.GetOrdinal("tipoHabitoId")),
                Nombre = reader.GetString(reader.GetOrdinal("Nombre"))
            };
        }
    }
}
